<template>
    <div style="height: 100%; width: 100%; position: relative;" ref="maindev">
        <div class="pagetop" :style="{ height: '65px' }">
            <table style="width: 100%; font-size: 12px;" border="0">
                <col style="width: 4%;" />
                <col style="width: 8%;" />
                <col style="width: 1%;" />
                <col style="width: 8%;" />
                <col style="width: 4%;" />
                <col style="width: 9%;" />
                <col style="width: 4%;" />
                <col style="width: 9%;" />
                <col style="width: 4%;" />
                <col style="width: 7%;" />
                <col style="width: 4%;" />
                <col style="width: 7%;" />
                <col style="width: 37%;" />
                <tr>
                    <td align="right">生成日期 </td>
                    <td>
                        <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;min-width: 100px;" @change=HasChange> </el-date-picker>
                    </td>
                    <td>至</td>
                    <td>
                        <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;min-width: 100px;" @change=HasChange> </el-date-picker>
                    </td>
                    <td align="right">送检医院</td>
                    <td>
                        <rm-ddl-common datatype="hospital" dataname="医院" v-model="searchobj.hospcode" width="100%" @change=HasChange></rm-ddl-common>
                    </td>
                    <td align="right">检验组</td>
                    <td colspan="1">
                        <rm-ddl-common v-model="searchobj.labgroupid" clearable filterable :appendtobody="true" visible-change:true datatype="labgroup" dataname="检验组" width="100%" @change="LabgroupChange" style="min-width: 100px;"></rm-ddl-common>
                    </td>
                    <td align="right">病历号</td>
                    <td>
                        <el-input size="small" style="width:100%;min-width:130px" v-model="searchobj.pat_no" @focus="Focus($event)" @input=HasChange></el-input>
                    </td>
                    <td align="right">姓名</td>
                    <td>
                        <el-input size="small" style="width:100%" v-model="searchobj.patname_py" @focus="Focus($event)" @input=HasChange></el-input>
                    </td>
                </tr>
                <tr>
                    <td colspan="13" align="right">
                        <el-button @click.native="BtnQuery" v-has="'PINQUERY'" type="primary" icon="el-icon-search">查询</el-button>
                        <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>
                        <el-button @click.native="BtnExport" v-has="'PEXPORT'" icon="el-icon-upload2">导出</el-button>
                        <el-button @click="BtnClose" icon="el-icon-close">退出</el-button>
                    </td>
                </tr>
            </table>
        </div>
        <div class="pagecenter" :style="{ top: '70px' }">
            <div class="middle-center">
                <vxe-table show-overflow="tooltip" ref="xTable" height="auto" border class="mytable-style" :loading="bLoading" :sort-config="{trigger: 'cell'}" :data.sync="tableData" size="mini" highlight-current-row highlight-hover-row resizable stripe header-align="center" :key="xTableKey" :row-class-name="RowClassName" :span-method="RowSpanMethod">
                    <vxe-table-column field="rptunitname" sortable title="报告单元" width="130" show-overflow></vxe-table-column>
                    <vxe-table-column field="sampleno" title="标本号" width="110" header-align="center"></vxe-table-column>
                    <vxe-table-column field="rpt_itemname" sortable title="检验项目" width="160" show-overflow></vxe-table-column>
                    <vxe-table-column field="result_str" sortable title="检验结果" width="70" header-align="center" align="right" show-overflow></vxe-table-column>
                    <vxe-table-column field="result_str" sortable title="违反规则" width="80" header-align="center" align="right" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_name" align="center" sortable title="姓名" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_sexname" align="center" sortable title="性别" width="35" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_agestr" align="center" sortable title="年龄" width="40" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_no" sortable title="病人号" width="110" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_deptname" sortable title="申请科室" width="120" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_wardname" sortable title="病区" width="120" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_bedno" align="center" sortable title="床号" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="result_dt" align="center" sortable title="结果时间" width="125" show-overflow></vxe-table-column>
                    <vxe-table-column field="createdt" align="center" sortable title="生成时间" width="125" show-overflow></vxe-table-column>
                    <vxe-table-column field="transuername" align="center" sortable title="确认人" width="70" show-overflow></vxe-table-column>
                    <vxe-table-column field="transdt" align="center" sortable title="确认时间" width="125" show-overflow></vxe-table-column>
                    <vxe-table-column field="cp_transmin" sortable title="确认耗时(分钟)" width="100" header-align="center" align="right"  show-overflow></vxe-table-column>
                    <vxe-table-column field="transcomm" sortable title="确认信息" width="150" show-overflow></vxe-table-column>
                    <vxe-table-column field="specimen_name" sortable title="样本类型" width="100" show-overflow></vxe-table-column>
                    <vxe-table-column align="center" field="sampledate" sortable title="标本日期" width="70" :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow></vxe-table-column>
                    <vxe-table-column field="createby" sortable title="生成模块" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="pat_diag" sortable title="临床诊断" width="250" show-overflow></vxe-table-column>
                    <vxe-table-column field="rptunitid" sortable title="单元ID" width="60" show-overflow></vxe-table-column>
                    <vxe-table-column field="reportid" sortable title="报告单ID" width="120" header-align="center" align="left" show-overflow></vxe-table-column>
                    <vxe-table-column field="req_docname" sortable title="申请医生" width="80" align="center" show-overflow></vxe-table-column>
                </vxe-table>
            </div>
        </div>
    </div>
</template>

<script type="text/javascript">
import XE from "xe-utils";
export default {
    name: "LIS415",
    data() {
        return {
            bLoading: false,
            xTableKey: 0,
            tableData: [],
            searchobj: {
                //查询框初始值
                //reqdate
                strdate: XE.toDateString(XE.getWhatDay(new Date(), -1), "yyyy-MM-dd"), //开始日期
                enddate: XE.toDateString(new Date(), "yyyy-MM-dd"), //结束日期
                hospcode: "", //送检医院
                labgroupid: "", //检验工作组
                pat_no: "", //病历号
                patname_py: "", //病人姓名
            },
        };
    },
    created() {
        this.GetLabgroupid();
    },
    methods: {
        //获取用户检验组
        async GetLabgroupid() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS415",
                    method: "post",
                    data: {
                        action: "defaultLabgroupid",
                    },
                });
                if (res != -1) {
                    this.searchobj.labgroupid =  XE.toString(res);
                }
            } catch (e) {
                this.$alert(e);
            }
        },
        /****************  按钮类 ********************/
        //查询
        async BtnQuery() {
            this.bLoading = true;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS415",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "query",
                        ...this.searchobj,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        this.tableData = res.Data;
                        this.bLoading = false;
                    } else {
                        this.tableData = [];
                        this.bLoading = false;
                    }
                })
                .catch((e) => {
                    this.bLoading = false;
                    this.$alert(e, { type: "error" });
                });
        },
        //清除
        BtnClear() {
            this.searchobj = {
                strdate: XE.toDateString(XE.getWhatDay(new Date(), -1), "yyyy-MM-dd"), //开始日期
                enddate: XE.toDateString(new Date(), "yyyy-MM-dd"), //结束日期
                hospcode: "", //送检医院
                labgroupid: "", //检验工作组
                pat_no: "", //病历号
                patname_py: "", //病人姓名
            };
            this.tableData = [];
        },
        //导出
        BtnExport() {
            let options = {
                filename: "LIS415 危急值内部提醒查询.csv",
            };
            this.$refs.xTable.exportCsv(options);
        },
        //关闭
        BtnClose() {
            let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "LIS415");
            this.$parent.$refs.itemtags.tagsList.splice(index, 1);
            this.$router.go(-1);
        },
        /*****************CLASS*********************/
        RowClassName({ row }) {
            if (row.transdt != null) return "rm-disable";
        },
        /****************  其他类 ********************/
        //点击触发文本内容全选
        Focus(event) {
            event.currentTarget.select();
        },
        //检验工作组改变事件
        LabgroupChange(code, name) {
            this.searchobj.labgroupid = code;
            this.searchobj.labgroupname = name;
            this.tableData = [];
        },
        //查询条件改变，清空表格数据
        HasChange() {
            this.tableData = [];
        },
         // 通用行合并函数（将相同多列数据合并为一行）
        RowSpanMethod({ row, $rowIndex, column, data }) {
            let fields = ["rptunitname", "sampleno","sampledate","rptunitid"];
            let cellValue = row[column.property];
            if (cellValue && fields.includes(column.property)) {
                let prevRow = data[$rowIndex - 1];
                let nextRow = data[$rowIndex + 1];
                if (prevRow && prevRow[column.property] === cellValue) {
                    return { rowspan: 0, colspan: 0 };
                } else {
                    let countRowspan = 1;
                    while (nextRow && nextRow[column.property] === cellValue) {
                        nextRow = data[++countRowspan + $rowIndex];
                    }
                    if (countRowspan > 1) {
                        return { rowspan: countRowspan, colspan: 1 };
                    }
                }
            }
        },
    },
};
</script>

<style scoped>
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
    white-space: nowrap;
}
.pagetop {
    width: 100%;
    height: 120px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}
.pagecenter {
    position: absolute;
    top: 125px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}
.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 0px;
    overflow: auto;
}
::v-deep .mytable-style .vxe-body--row.row-blue {
    color: rgb(157, 158, 161) !important;
    font-weight: bold;
}
::v-deep .el-icon-time {
    line-height: 18px !important;
}
::v-deep .el-range__close-icon {
    line-height: 18px !important;
}
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 0px;
}
::v-deep .el-checkbox__label {
    display: inline-block;
    font-size: 12px;
}
::v-deep .vxe-table .vxe-cell {
    padding: 0 3px 0 3px !important;
}
::v-deep tr.vxe-body--row.row--current {
    color: #000000;
    font-weight: bold;
}
</style>